﻿using Engine;
using Game;
using GameEntitySystem;
using TemplatesDatabase;

namespace SAGhoul
{
    public class ComponentBulletDefender : Component
    {
        public ComponentCreature ComponentCreature
        {
            get; set;
        }
        public float HeadHitDamageMultiplier
        {
            get; set;
        }
        public float NonHeadHitDamageMultiplier
        {
            get; set;
        }

        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            base.Load(valuesDictionary, idToEntityMap);
            ComponentCreature = Entity.FindComponent<ComponentCreature>(throwOnError: true);
            HeadHitDamageMultiplier = valuesDictionary.GetValue("HeadHitDamageMultiplier", 1.5f);
            NonHeadHitDamageMultiplier = valuesDictionary.GetValue("NonHeadHitDamageMultiplier", 1f);
        }

        /// <summary>
        /// 通过击中点坐标判断是否爆头
        /// </summary>
        /// <param name="hitPoint"></param>
        /// <returns></returns>
        public bool HitHead(Vector3 hitPoint)
        {
            return MathUtils.Abs(ComponentCreature.ComponentCreatureModel.EyePosition.Y - hitPoint.Y) <= 0.15f;
        }
    }
}